package canchaFulbito.servletacceso;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import junit.framework.Assert;
import canchaFulbito.excepcion.DAOExcepcion;
import canchaFulbito.modelo.Cancha;
import canchaFulbito.negocio.SeguridadNegocio;

/**
 * Servlet implementation class SearchServlet
 */
public class SearchServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SearchServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		SeguridadNegocio neg = new SeguridadNegocio();
		int idDistrito =Integer.parseInt(request.getParameter("distrito"));
		String dia1 =request.getParameter("dia1");		
		String dia2 =request.getParameter("dia2");
		String hora1 =request.getParameter("hora1");
		String hora2 =request.getParameter("hora2");
		
		//String ms= idDistrito +" "+ dia1 +" "+ dia2 +" "+ hora1 +" "+ hora2;
		
		try {
			//Collection<Cancha> encontrados = neg.buscarCancha(idDistrito,txtDia,txtHora);			
			request.setAttribute("canchas", neg.buscarCancha(idDistrito,dia1,dia2,hora1,hora2));
			RequestDispatcher rd = request.getRequestDispatcher("resultado.jsp");
			rd.forward(request, response);

		} catch (DAOExcepcion e) {
			//Assert.fail("Falló: " + e.getMessage());
			e.printStackTrace();
		}
		
	}

}

